#include<iostream>
using namespace std;

template <typename T>
void rswap(T &left, T &right) {
   T temp=left;
   left=right;
   right=temp;
}

template <typename T>
void pswap(T *left, T *right) {
   T *temp=left;
   left=right;
   right=temp;
}
template <typename T>
void ppswap(T **left, T **right) {
   T *temp=*left;
   *left=*right;
   *right=temp;
}

int main() {
   int i=10, j=20;
   cout<<i<<", "<<j<<endl;
   rswap(i, j);
   cout<<i<<", "<<j<<endl;
   pswap(&i, &j);
   cout<<i<<", "<<j<<endl;

   int *pi=&i, *pj=&j; 
   //] pi, pj are of type 'int *', 
   //] their values are address of i, address of j

   cout<<*pi<<", "<<*pj<<endl;
   ppswap(&pi, &pj);
   cout<<*pi<<", "<<*pj<<endl;
   rswap(pi, pj);
   cout<<*pi<<", "<<*pj<<endl;
}
